package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.GameDetailsRecord;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.GameDetailsRecordService;
import org.hxyjs.vo.GameDetailsRecordView;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller //@Controller注解是用spring容器生成 对象 默认对象名 gameDetailsRecordController
//@RequestMapping("/gameDetailsRecordController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /gameDetailsRecordController
public class GameDetailsRecordController {
	@Resource
    GameDetailsRecordService gameDetailsRecordService;

	@GetMapping("/gameDetailsRecords")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<GameDetailsRecord> getAllGameDetailsRecord() throws Exception{
    	System.out.println("查询全部专家");
    	return gameDetailsRecordService.getAllGameDetailsRecords();
    }

	@PostMapping("/gameDetailsRecord")
	@ResponseBody
	public DTO<GameDetailsRecord> addGameDetailsRecord(@RequestBody GameDetailsRecord gameDetailsRecord) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加专家成功");
		return gameDetailsRecordService.addGameDetailsRecord(gameDetailsRecord);
	}
	@DeleteMapping("/gameDetailsRecord/{gdrno}")
	@ResponseBody
    public DTO<GameDetailsRecord> deleteGameDetailsRecordByGdrno(@RequestBody @PathVariable("gdrno") String gdrno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(gdrno+"删除专家成功");
    	return gameDetailsRecordService.deleteGameDetailsRecordByGdrno(gdrno);
    }

	@GetMapping("/gameDetailsRecord/{gdrno}")
	@ResponseBody
	public DTO<GameDetailsRecord> getGameDetailsRecordByGdrno(@PathVariable("gdrno") String gdrno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println(gdrno+"根据主键查询专家成功");
		return gameDetailsRecordService.getGameDetailsRecordByGdrno(gdrno);
	}

	@PatchMapping("/gameDetailsRecord")
	@ResponseBody
	public DTO<GameDetailsRecord> updateGameDetailsRecordByGdrno(@RequestBody GameDetailsRecordView gameDetailsRecordViewa) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改专家成功");
		return gameDetailsRecordService.updateGameDetailsRecordByGdrno(gameDetailsRecordViewa);
	}

	@RequestMapping("/gameDetailsRecords/pageInfo")
	@ResponseBody
	public DTO<GameDetailsRecord> getGameDetailsRecordByPage(@SpringQueryMap PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("查询分页");
		return gameDetailsRecordService.getGameDetailsRecordByPage(pageInfo);
	}

}
